<%@page language="java" contentType="text/html;charset=UTF-8"%>
<%@include file="/common/include.jsp"%>
<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
    <link href="${ctx }/bootstrap/css/login.min.css" rel="stylesheet">
	<title>文件</title>
	<!-- <script>
		if(window.top!==window.self){window.top.location=window.location};
	</script> -->
</head>
<body>
	<form id="myform" action="" enctype="multipart/form-data">
		<input type="file" name="file" id="file">
		<input type="button" id="sbt" name="sbt" value="提交">
		<div id="msg"></div>
	</form>
</body>
<script type="text/javascript">
	$(function(){
		
		$("#sbt").click(function(){
			var formData = new FormData($("#myform")[0]);
			$.ajax({
				url: '${ctx }/fileupload/upload.do',
				type: 'post',
				data: formData,
				contentType: false,
				processData: false,
				xhr:function(){
					var xhr = $.ajaxSettings.xhr();
					if(onprogress && xhr.upload) {
						xhr.upload.addEventListener("progress" , onprogress, false);
						return xhr;
					}
				},
				success: function (data) {
					layer.msg('上传成功', {timeout:1000});
				}
			});
		});
		
		function onprogress(e){
			$("#msg").html("已加载：" + e.loaded + "总共：" + e.total + "完成率：" + Math.ceil(e.loaded*100/e.total) + "%");
		}
		
	});
</script>
</html>